import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuex/index'

Vue.use(Router)

//布局页路由
const layout = [
    {
        path: '/',
        component: resolve => require(['../views/home/index.vue'], resolve),
        meta: { requireAuth: false }
    },
    {
        path: '/index111',
        component: resolve => require(['../components/hscroll.vue'], resolve),
        meta: { requireAuth: false }
    },
    {
        path: '/resetPwd',//重置密码
        component: resolve => require(['../views/home/resetPwd.vue'], resolve),
        meta: { title: '重置密码', permission: true }
    },
    {
        path: '/tabs',//右边的选项卡
        component: resolve => require(['../views/Tabs.vue'], resolve),
        meta: { title: 'tab选项卡' }
    }
]
//主路由
const routes = [
    {
        path: '/',
        component: resolve => require(['../views/login.vue'], resolve)
    },
    {
        path: '/index',
        component: resolve => require(['../components/common/Home.vue'], resolve),
        meta: { title: '自述文件' },
        //children: systemRoute.concat(subRoute)//合并
        children:layout
    },
    //带底部主页
    {
        path: '/layout',
        component: resolve => require(['../views/layout/layout.vue'], resolve),
        children: layout
    },
    {
        path: '*',
        component: resolve => require(['../views/NotFind.vue'], resolve),
    },//全不匹配的情况下，返回404，路由按顺序从上到下，依次匹配。最后一个*能匹配全部，
]

const router = new Router({
    hashbang: true,
    history: true,
    transitionOnLoad: true,
    routes
});
/*页面刷新重新赋值commmon*/
//给公共参数重新赋值
if (hgetStore("common")) {
    console.log(JSON.parse(hgetStore("common")));
    store.dispatch("editcommon", JSON.parse(hgetStore("common")));
}
//方便修改
function heditcommon(obj) {
    store.dispatch("editcommon", obj);
}
window.heditcommon = heditcommon;
//拦截
router.beforeEach((to, from, next) => {
    // console.log(to);
    // console.log(from);
    // console.log(next);
    next();
    //return; //判断是否需要登录
    // if (to.matched.some(record => record.meta.requireAuth)) {
    //     //判断Token
    //     if (store.state.token) {
    //         //需要引入store
    //         next();
    //     } else {
    //         //Token失效
    //         next({ path: '/login' });
    //     }
    // } else {
    //     next();
    // }
});


export default router;